package com.example.bookstore.controller;

import com.example.bookstore.accessctro.RolePermission;
import com.example.bookstore.entity.BookUser;
import com.example.bookstore.entity.Product;
import com.example.bookstore.form.bookform.InsertBookForm;
import com.example.bookstore.form.bookform.UpdateBookForm;
import com.example.bookstore.form.userform.RegisterForm;
import com.example.bookstore.service.BookService;
import com.example.bookstore.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;

@Slf4j
@Api(value = "用户操作接口", tags = {"图书产品信息管理"})
@RestController
@RequestMapping("/BookController")
public class BookController {

    @Autowired
    BookService bookService;

    @ApiOperation("添加图书商品")
    @PostMapping("/InsertBook")
    public ResultVO InsertBook(InsertBookForm insertBookForm) {
        return bookService.InsertBook(insertBookForm);
    }

    @RolePermission(key = "超级用户")
    @ApiOperation("编辑图书商品")
    @PostMapping("/UpdateBook")
    public ResultVO UpdateBook(UpdateBookForm updateBookForm) {
        return bookService.UpdateBook(updateBookForm);
    }

    @ApiOperation("更新图书图片")
    @PostMapping("/UpdateBookImg")
    public ResultVO UpdateBookImg(@RequestParam(value = "file") MultipartFile file,Integer productId) {
        return bookService.UpdateBookImg(file, productId);
    }

    @ApiOperation("删除下架图书商品")
    @PostMapping("/DeleteBook")
    public ResultVO DeleteBook(Integer productId) {
        return bookService.DeleteBook(productId);
    }

    @ApiOperation("根据id精确查询图书商品")
    @PostMapping("/SelectBookById")
    public ResultVO SelectBookById(Integer productId) {
        return bookService.SelectBookById(productId);
    }

    @ApiOperation("按类别查询图书")
    @PostMapping("/SelectBookByClass")
    public ResultVO SelectBookByClass(String productClass) {
        return bookService.SelectBookByClass(productClass);
    }

    @ApiOperation("按书名模糊查询图书")
    @PostMapping("/SelectBookByName")
    public ResultVO SelectBookByName(String productName) {
        return bookService.SelectBookByName(productName);
    }

    @ApiOperation("随机列出20本图书")
    @PostMapping("/ShowRandomBook")
    public ResultVO ShowRandomBook() {
        return bookService.ShowRandomBook();
    }

    @ApiOperation("显示所有图书")
    @PostMapping("/ShowAllBook")
    public ResultVO ShowAllBook() {
        return bookService.ShowAllBook();
    }


}
